package com.anycc.cloud.common.dto.datatable;

import com.anycc.cloud.common.dto.query.OrderBy;
import com.anycc.cloud.common.dto.query.PagingRequest;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * datatable request
 */
@Data
public class DataTableRequest {
    private Integer draw = 0;
    private Integer start = 0;
    private Integer length = 10;
    private List<OrderBy> orders = new ArrayList<>();

    public DataTableRequest() {
    }


    public PagingRequest buildPageRequest() {
        return new PagingRequest(this.start / this.length, this.length, this.orders);
    }

    public PagingRequest buildPageRequest(List<OrderBy> orderByList) {
        this.orders.addAll(orderByList);
        return new PagingRequest(this.start / this.length, this.length, this.orders);
    }

    public PagingRequest buildPageRequest(OrderBy orderBy) {
        this.orders.add(orderBy);
        return new PagingRequest(this.start / this.length, this.length, this.orders);
    }
}
